package com.jk.dailydemo.Share;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.jk.dailydemo.MainActivity;
import com.jk.dailydemo.R;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.shareboard.SnsPlatform;
import com.umeng.socialize.utils.SocializeUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by jk on 2017/6/2.
 */

public class ShareDemoActivity extends AppCompatActivity {
    @BindView(R.id.btn_share_1)
    Button mBtnShare1;

    private UMImage imageurl,imagelocal;
    private SHARE_MEDIA share_media;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share_demo);
        ButterKnife.bind(this);
//        share_media = (SHARE_MEDIA) getIntent().getSerializableExtra("platform");
        share_media = SHARE_MEDIA.QZONE.toSnsPlatform().mPlatform;
//        share_media = SHARE_MEDIA.QQ.toSnsPlatform().mPlatform;
        initMedia();
    }

    @OnClick({R.id.btn_share_1,R.id.btn_share_2})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.btn_share_1:
                new ShareAction(ShareDemoActivity.this).withText("hello")
                        .setDisplayList(SHARE_MEDIA.SINA,SHARE_MEDIA.QQ, SHARE_MEDIA.WEIXIN)
                        .setCallback(umShareListener).open();

//                new ShareAction(ShareDemoActivity.this)
//                        .setPlatform(share_media)
//                        .withMedia(imagelocal )
//                        .setCallback(shareListener)
//                        .share();

                break;
            case R.id.btn_share_2:
               new ShareAction(ShareDemoActivity.this)
                        .setPlatform(SHARE_MEDIA.QQ)
                        .withText("hello")
                        .setCallback(umShareListener)
                        .share();
                break;

        }

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);

    }

    private void initMedia(){
        imageurl = new UMImage(this,"https://mobile.umeng.com/images/pic/home/social/img-1.png");
        imageurl.setThumb(new UMImage(this, R.mipmap.ic_launcher));
        // imagelocal = new UMImage(this,R.drawable.logo,umImageMark);
        imagelocal = new UMImage(this,R.mipmap.ic_launcher);
        imagelocal.setThumb(new UMImage(this, R.mipmap.ic_launcher));
    }
    public ArrayList<String> styles = new ArrayList<String>();



    private UMShareListener shareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA platform) {
//            SocializeUtils.safeShowDialog(dialog);
        }

        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(ShareDemoActivity.this,"成功了",Toast.LENGTH_LONG).show();
//            SocializeUtils.safeCloseDialog(dialog);
        }

        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
//            SocializeUtils.safeCloseDialog(dialog);
            Toast.makeText(ShareDemoActivity.this,"失败"+t.getMessage(),Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCancel(SHARE_MEDIA platform) {
//            SocializeUtils.safeCloseDialog(dialog);
            Toast.makeText(ShareDemoActivity.this,"取消了",Toast.LENGTH_LONG).show();

        }
    };






    UMShareListener umShareListener = new UMShareListener() {
        @Override
        public void onStart(SHARE_MEDIA share_media) {
            SnsPlatform snsPlatform = share_media.toSnsPlatform();
            SHARE_MEDIA platform = SHARE_MEDIA.SINA.toSnsPlatform().mPlatform;
            if (share_media == SHARE_MEDIA.QZONE.toSnsPlatform().mPlatform){
                Toast.makeText(ShareDemoActivity.this,"QZONE",Toast.LENGTH_LONG).show();
            }else if (share_media == SHARE_MEDIA.WEIXIN.toSnsPlatform().mPlatform){


            }else if(share_media == SHARE_MEDIA.SINA.toSnsPlatform().mPlatform){
                Toast.makeText(ShareDemoActivity.this,"SINA",Toast.LENGTH_LONG).show();
            }

        }

        @Override
        public void onResult(SHARE_MEDIA share_media) {

        }

        @Override
        public void onError(SHARE_MEDIA share_media, Throwable throwable) {

        }

        @Override
        public void onCancel(SHARE_MEDIA share_media) {
            SnsPlatform snsPlatform = share_media.toSnsPlatform();
            String icon = snsPlatform.mIcon;
            String showWord = snsPlatform.mShowWord;
        }
    };

//    private ShareAction ShareAction(ShareDemoActivity shareDemoActivity) {
//        return null;
//    }
}
